import router from '@/router'
//路由进入前拦截
//to:将要进入的页面， from 将要离开的页面， next放行
const whiteList = ['/login', '/404', '/401'] // no redirect whitelist
router.beforeEach(async (to) => {
  const basicStore = useBasicStore()
  //1.判断token
  if (basicStore.token) {
    if (to.path === '/login') {
      return '/'
    } else {
      //1.判断token
      if (basicStore.token) {
        if (to.path === '/login') {
          return '/'
        } else {
          basicStore.setFilterAsyncRoutes([])
          return true
        }
      } else {
        if (!whiteList.includes(to.path)) {
          return `/login?redirect=${to.path}`
        } else {
          return true
        }
      }
    }
  } else {
    if (!whiteList.includes(to.path)) {
      return `/login?redirect=${to.path}`
    } else {
      return true
    }
  }
})
//路由进入后拦截
router.afterEach(() => {})
